package leetcode.offer_two_special.hash;

import java.util.Arrays;
import java.util.List;

/**
 * 输入：timePoints = ["23:59","00:00"]
 * 输出：1
 * <p>
 * https://leetcode-cn.com/problems/569nqc/
 *
 * @author mazouri
 * @create 2021-09-10 9:59
 */
public class _35_findMinDifference {
    public int findMinDifference(List<String> timePoints) {
        if (timePoints.size() > 1440) return 0;

        int[] times = new int[timePoints.size()];
        for (int i = 0; i < timePoints.size(); i++) {
            String t = timePoints.get(i);
            times[i] = t.charAt(0) * 600 + t.charAt(1) * 60 + t.charAt(3) * 10 + t.charAt(4);
        }

        Arrays.sort(times);
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < timePoints.size() - 1; i++) {
            min = Math.min(min, times[i + 1] - times[i]);

            if (min == 0) return 0;
        }
        return Math.min(min, 1440 - times[timePoints.size() - 1] + times[0]);
    }
}
